//
//  CGQyujingchuliViewController.swift
//  SheYangBigData
//
//  Created by 叁拾叁 on 2021/5/11.
//  Copyright © 2021 叁拾叁. All rights reserved.
//


import UIKit
import MJRefresh
import RxSwift
import RxDataSources
import Then
import SDCycleScrollView
import IQKeyboardManagerSwift
import SwiftDate

class CGQyujingchuliViewController: SYBaseViewController {
    
    
    var  model: CGQshebeiinfoModel!

//
    
    var  dicParams: [String : String] = [:]
    
    
    var id: String!
    
    init(id: String) {
        super.init(nibName: nil, bundle: nil)
        self.id = id
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    var timeView: UIView = {
        let v = UIView()
        v.layer.borderColor = UIColor(hex: 0xFFFFFF).cgColor
        v.layer.shadowRadius = 5
        v.layer.borderWidth = 1
        v.layer.masksToBounds = true
        v.backgroundColor = .white
        return v
    }()
    
    
    let tipText: UILabel = {
        let v = UILabel()
        v.text = "处理时间"
        v.font = 14.autoBoldFontSize()
        v.textColor = UIColor(hex: 0x333333)
        return v
    }()
    var tlineView: UIView = {
        let v = UIView()
        v.backgroundColor = UIColor(hex: 0xEBEBEB)
        return v
    }()
    
    let nameTf: UITextField = {
        let v:UITextField = UITextField()
        v.textColor = UIColor(hex: 0x333333)
        v.font = 14.autoFontSize()
        v.placeholder = "请选择时间"
        v.textAlignment = .right
        return v
    }()
    
    var tixianBt: UIButton = {
        let v = UIButton()
        return v
    }()
    let tarrowView: UIImageView = {
        let v = UIImageView()
        v.image = UIImage(named: "arrow_gray")
        return v
    }()
    
    var remaksView: UIView = {
        let v = UIView()
        v.layer.borderColor = UIColor(hex: 0xffffff).cgColor
        v.backgroundColor = .white
        v.layer.shadowRadius = 5
        v.layer.masksToBounds = true
        return v
    }()
    
    
    let remarksText: UILabel = {
        let v = UILabel()
        v.text = "处理内容"
        v.font = 14.autoBoldFontSize()
        v.textColor = UIColor(hex: 0x333333)
        return v
    }()
    var rlineView: UIView = {
        let v = UIView()
        v.backgroundColor = UIColor(hex: 0xEBEBEB)
        return v
    }()
    
    let remarkstv: EWTextView = {
        let v:EWTextView = EWTextView()
        v.textColor = UIColor(hex: 0x333333)
        v.font = 14.autoFontSize()
        v.textAlignment = .left
        v.placeHolder = "请输入设备备注信息"
        
        v.placeHolderColor = UIColor(hex: 0x999999)
        return v
    }()
    
    
    var delete: UIButton = {
        let v = UIButton()
        v.setTitle("保存", for: .normal)
        v.setTitleColor(UIColor.white, for: .normal)
        v.titleLabel?.font = 18.autoFontSize()
        v.layer.cornerRadius = 3
        v.layer.masksToBounds = true
        v.backgroundColor = UIColor(hex: 0x0782FF)
        return v
    }()
 
    
    override func viewDidLoad() {
        super.viewDidLoad()
        initViews()
//        setupViewModel()
        self.title = "预警处理"
        self.view.backgroundColor = Constant.bgViewColor
        IQKeyboardManager.shared.enable = true
        IQKeyboardManager.shared.enableAutoToolbar = true
        
        tixianBt.addAction {
            [weak self] in
            if let `self` = self {
            
                
                self.setupSheet()
            }
            
        }
        
        
        delete.addAction {
            [weak self] in
            if let `self` = self {
                
                
                
                self.dicParams["dealTime"] = self.nameTf.text
                self.dicParams["dealDescription"] =  self.remarkstv.text
                self.dicParams["id"] = self.id
                self.requestVM.baseRequest(disposeBag: self.dispose, type: .editYJchuli(dic: self.dicParams), modelClass: SGBaseModel<CGQshebeiinfoModel>.self) {[weak self] (res) in
                    
                    if let `self` = self  {
                
                        self.popVC()
                        
        //                self.loadDataSuccessed()
                    }
                    
                } Error: {
                    
                }
                
            }
            
        }
    }
    
    
    
    
    func setupSheet() {
        
        let dialog:WMZDialog = Dialog()
        dialog.wDateTimeTypeSet()  ("yyyy年MM月dd日HH时mm分ss秒") //("yyyy-MM-dd HH:mm:ss")
        .wDefaultDateSet()(Date())
        .wEventOKFinishSet()({(anyId:Any?,otherData:Any?)in
            print("点击确定",anyId as Any,otherData as Any);
            let datefmatter = DateFormatter()
            datefmatter.dateFormat="yyyy年MM月dd日HH时mm分ss秒"
            let date = datefmatter.date(from: otherData as! String )
            
            datefmatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
            
            
            print("当前日期时间：\(datefmatter.string(from: date!))")
            
            self.nameTf.text = datefmatter.string(from: date!)
            
//            let dateStamp:TimeInterval = date!.timeIntervalSince1970
//            let dateStr:Int = Int(dateStamp)
    
            
            
            
//            [dateFormatter stringFromDate:date]
            
                
            
        })
        .wTypeSet()(DialogTypeDatePicker);
        _ = dialog.wStart()

        
    }
    
    
    @objc func rightAction() {
        
    }
    
    fileprivate func setupViewModel() {
        
        requestVM.baseRequest(disposeBag: dispose, type: .sheDetail(id: self.id), modelClass: SGBaseModel<CGQshebeiinfoModel>.self) {[weak self] (res) in
            
            if let `self` = self  {
                self.model = res.data ?? CGQshebeiinfoModel()
      

            }
            
        } Error: {
            
        }
    }
    
    
    
    
    
//    @objc func saveEditInfo(btn:UIButton){
//
//        if nameTf.text?.length == 0 {
//
//
//            return
//
//        }
//
//
//        self.dicParams["dealTime"] = nameTf.text
//        self.dicParams["dealDescription"] = self.model.deviceId
//
//
//        print(self.dicParams ?? "")
//
//        requestVM.baseRequest(disposeBag: dispose, type: .editDeviceDetail(dic: self.dicParams), modelClass: SGBaseModel<CGQshebeiinfoModel>.self) {[weak self] (res) in
//
//            if let `self` = self  {
//
//                self.popVC()
//
////                self.loadDataSuccessed()
//            }
//
//        } Error: {
//
//        }
//
//
//    }
    
    func initViews() {
    
        view.addSubview(timeView)
        view.addSubview(remaksView)
        view.addSubview(delete)
        timeView.addSubview(tipText)
        timeView.addSubview(tlineView)
        timeView.addSubview(nameTf)
        timeView.addSubview(tarrowView)
        timeView.addSubview(tixianBt)
        
        remaksView.addSubview(remarksText)
        remaksView.addSubview(rlineView)
        remaksView.addSubview(remarkstv)
        
        timeView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(NAV_HEIGHT+autoWidth(10))
            make.left.equalToSuperview().offset(autoWidth(10))
            make.right.equalToSuperview().offset(autoWidth(-10))
//            make.height.equalTo(86.autoWidth())
        }
        
        tipText.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(autoWidth(13))
            make.left.equalToSuperview().offset(autoWidth(10))
            make.right.equalToSuperview().offset(autoWidth(-10))
        }
        
        tixianBt.snp.makeConstraints { (make) in
            
            make.top.bottom.left.right.equalToSuperview()
        }
        
        tlineView.snp.makeConstraints { (make) in
            make.top.equalTo(tipText.snp.bottom).offset(autoWidth(13))
            make.left.equalToSuperview()
            make.right.equalToSuperview()
            make.height.equalTo(1)
        }
        nameTf.snp.makeConstraints { (make) in
            make.top.equalTo(tlineView.snp.bottom).offset(autoWidth(13))
            make.left.equalToSuperview().offset(15)
            make.bottom.equalToSuperview().offset(autoWidth(-14))
        }
        
        tarrowView.snp.makeConstraints { (make) in
            
            make.centerY.equalTo(nameTf.snp.centerY)
            make.height.equalTo(14.autoWidth() )
            make.width.equalTo(8.autoWidth())
            make.right.equalTo(-15.autoWidth())
        }
        remaksView.snp.makeConstraints { (make) in
            make.top.equalTo(timeView.snp.bottom).offset(autoWidth(13))
            make.left.equalToSuperview().offset(autoWidth(10))
            make.right.equalToSuperview().offset(autoWidth(-10))
            
        }
        
        
        remarksText.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(autoWidth(10))
            make.left.equalToSuperview().offset(autoWidth(10))
            make.right.equalToSuperview().offset(autoWidth(-10))
        }
        
        
        
        
        rlineView.snp.makeConstraints { (make) in
            make.top.equalTo(remarksText.snp.bottom).offset(autoWidth(13))
            make.left.equalToSuperview()
            make.right.equalToSuperview()
            make.height.equalTo(1)
        }
        remarkstv.snp.makeConstraints { (make) in
            make.top.equalTo(rlineView.snp.bottom).offset(autoWidth(13))
            make.left.equalToSuperview()
            make.right.equalToSuperview()
            make.height.equalTo(160.autoWidth())
            make.bottom.equalToSuperview().offset(autoWidth(-14))
        }
        
        
        
        delete.snp.makeConstraints { (make) in
            make.top.equalTo(remaksView.snp.bottom).offset(autoWidth(15))
            make.left.equalToSuperview().offset(10.autoWidth())
            make.right.equalToSuperview().offset(-10.autoWidth())
            make.height.equalTo(44.autoWidth())
        
        }
    }
    
    
    
    
    
    
}


//自定义Section
//struct ACGQshebeiinfoModelSection {
//    var header: String
//    var items: [Item]
//}
//
//extension ACGQshebeiinfoModelSection : AnimatableSectionModelType {
//    typealias Item = CGQshebeiinfoModel
//
//    var identity: String {
//        return header
//    }
//
//    init(original: ACGQshebeiinfoModelSection, items: [Item]) {
//        self = original
//        self.items = items
//    }
//}
//
//extension CGQshebeiinfoModel: IdentifiableType {
//    var identityw: String {
//        return id!
//    }
//
//    typealias Identityw = String
//}



